package tcpConn

import (
	"fmt"
	"server/appControl"
	"server/proto"
	"server/public"
)

/*
*  -*- coding:utf8 -*-
*
*
*
*  @Author  : chengms
*  @WebSite : chengms.com
*  @Email   : chengms2012@163.com
*  @TIME    : 2020/8/21 17:03
*  @File    : tcpClient.go
 */

func TcpClientServe(t *TcpServer, cc *proto.ClientConn, cmd proto.CommandBuf) {

	var err error

	switch cmd.CmdType {
	case proto.CmdHeartbeat:
		appControl.HandlerHearbeat(cc)
	case proto.CmdSend:
		err = appControl.HandlerSendChat(t, cc, cmd.Data)
	case proto.CmdLogin:
		err = appControl.HandlerLongin(cc, cmd.Data)
	case proto.CmdRegister:
		err = appControl.HandlerRegister(cc, cmd.Data)
	case proto.CmdGroup:
		err = appControl.HandlerGroupChat(cc, cmd.Data)
	case proto.CmdLeave:
		fmt.Println(cmd)
	case proto.CmdLogOut:
		fmt.Println(cmd)
	case proto.CmdStatus:
		fmt.Println(cmd)
	default:
		public.Loggerf.Info("cmd:%T %v not supported", cmd.CmdType, cmd.Data)
	}

	if err != nil {
		public.Loggerf.Info("handle cmd err:%v", err)
	}

}

/*
	// 系统操作
	CmdHeartbeat = 0x0100 // 心跳包
	CmdStatus    = 0x0102 // 获取状态

	// 用户操作相关
	CmdLogin     = 0x0200 // 登录
	CmdLogOut    = 0x0201 // 离线
	CmdRegister  = 0x0202 // 注册
	CmdAddFriend = 0x0203 // 添加好友
	CmdAddGroup  = 0x0204 // 添加群

	// 消息发送
	CmdSend      = 0x0300 // 发送聊天消息
	CmdBroadCase = 0x0301 // 广播
	CmdGroup     = 0x0302 // 群聊
	CmdLeave     = 0x0303 // 离开群聊
*/
